/*
 * Copyright (C) 2017 Honeywell, Inc. All Rights Reserved.
 */

package org.thanos.demo;

import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import org.thanos.demo.consumer.DemoConsumer;
import org.thanos.demo.producer.DemoProducer;

import java.util.concurrent.TimeUnit;


@Component
public class NatsBootstrapListener implements ApplicationListener<ApplicationReadyEvent> {

    @Autowired
    private DemoProducer producer;

    @Autowired
    private DemoConsumer consumer;

    @SneakyThrows
    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        consumer.consume();
        for (; ; ) {
            TimeUnit.SECONDS.sleep(1);
            producer.produce();
        }
    }
}
